﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CreativeMinds.StopForumSpam;
using CreativeMinds.StopForumSpam.Responses;

namespace TestApp {
	public partial class Form1 : Form {
		public Form1() {
			InitializeComponent();
		}

		private void testButton_Click(object sender, EventArgs e) {
			resultTextBox.Text = String.Empty;
			Client client = new Client(apiKeyTextBox.Text);

			Response response;
			if (!String.IsNullOrWhiteSpace(usernameTextBox.Text) && String.IsNullOrWhiteSpace(emailAddressTextBox.Text) && String.IsNullOrWhiteSpace(ipAddressTextBox.Text)) {
				response = client.CheckUsername(usernameTextBox.Text);
			}
			else if (String.IsNullOrWhiteSpace(usernameTextBox.Text) && !String.IsNullOrWhiteSpace(emailAddressTextBox.Text) && String.IsNullOrWhiteSpace(ipAddressTextBox.Text)) {
				response = client.CheckEmailAddress(emailAddressTextBox.Text);
			}
			else if (String.IsNullOrWhiteSpace(usernameTextBox.Text) && String.IsNullOrWhiteSpace(emailAddressTextBox.Text) && !String.IsNullOrWhiteSpace(ipAddressTextBox.Text)) {
				response = client.CheckIPAddress(ipAddressTextBox.Text);
			}
			else {
				response = client.Check(usernameTextBox.Text, emailAddressTextBox.Text, ipAddressTextBox.Text);
			}

			if (response.Success) {
				resultTextBox.Text = "Great" + Environment.NewLine;
				foreach (ResponsePart part in response.ResponseParts) {
					resultTextBox.Text += String.Format("Appears: {0}, Freq: {1}, Last seen: {2}, type: {3}" + Environment.NewLine, part.Appears, part.Frequency, part.LastSeen, part.Type);
				}
			}
			else {
				resultTextBox.Text = String.Format("Result: {0}, error was: {1}", response.Success, ((FailResponse)response).Error);
			}
		}
	}
}